﻿using Dapper;
using huaxin_Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace huaxin_DAO
{
    public class huaxin_UserDao
    {

        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
        public int AddUser(huaxin_users users)
        {

            using (IDbConnection conn = SqlConn.OpenConnectionStar())
            {
                return  conn.QueryFirstOrDefault<int>("Pro_WxFollowUser", new
                {
                    OpenId=users.OpenId,
                    NickName=users.NickName,
                    Sex=users.Sex,
                    HeadImgUrl=users.HeadImgUrl,
                    Province=users.Province,
                    City=users.City,
                    Country=users.Country,
                    Address=users.Address,
                    Phone=users.Phone,
                    ZipCode=users.ZipCode

                }, null, null, CommandType.StoredProcedure);
            }
        }

        /// <summary>
        /// 获取关注用户信息
        /// </summary>
        /// <param name="openId"></param>
        /// <returns></returns>
        public huaxin_users GetModel(string openId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select top 1 * from huaxin_users where openId=@openID");

            using (IDbConnection conn = SqlConn.OpenConnectionStar())
            {
                return  conn.QueryFirstOrDefault<huaxin_users>(strSql.ToString(), new
                {
                    OpenId = openId
                }, null, null);
            }
        }

    }
}
